<?php
  class DateUtil{
      public function __construct(){    
      }
      
      /**
      * 将时间转换为 YY-MM-DD 格式
      * 
      * @param mixed $timestamp
      * @return string
      */
      public static function get_YY_mm_dd($timestamp = 0){
          date_default_timezone_set("Asia/Shanghai");
          if(is_int($timestamp)){
              $timestamp = ($timestamp == 0) ? time() : $timestamp;
              return date('Y-m-d',$timestamp);
          }
          if(is_string($timestamp)){
              return date('Y-m-d',strtotime($timestamp)); 
          }
      }
      
      /**
      * 将时间转换为 YY-MM 格式
      * 
      * @param mixed $timestamp
      * @return string
      */
      public static function get_YY_mm($timestamp = 0){
          date_default_timezone_set("Asia/Shanghai");
          if(is_int($timestamp)){
              $timestamp = ($timestamp == 0) ? time() : $timestamp;
              return date('Y-m',$timestamp);
          }
          if(is_string($timestamp)){
              return date('Y-m',strtotime($timestamp)); 
          }
      }
         
      /**
      * 将时间转换为 HH_mm_ss 格式
      * 
      * @param mixed $timestamp
      * @return string
      */
      public static function get_HH_mm_ss($timestamp = 0){
          date_default_timezone_set("Asia/Shanghai");
          if(is_int($timestamp)){
              $timestamp = ($timestamp == 0) ? time() : $timestamp;
              return date('H:i:s',$timestamp);
          }
          if(is_string($timestamp)){
              return date('H:i:s',strtotime($timestamp)); 
          }                               
      }
      
      /**
      * 将时间转换为 YY_mm_dd_HH_mm_ss 格式
      * 
      * @param mixed $timestamp
      * @return string
      */
      public static function get_YY_mm_dd_HH_mm_ss($timestamp = 0){
          date_default_timezone_set("Asia/Shanghai");
          if(is_int($timestamp)){
              $timestamp = ($timestamp == 0) ? time() : $timestamp;
              return date('Y-m-d H:i:s',$timestamp);
          }
          if(is_string($timestamp)){
              return date('Y-m-d H:i:s',strtotime($timestamp));
          }
      }
  }
?>
